/* Copyright © 2010 LPRM
Universidade Federal do Espírito Santo - RNP-GT CWTools

This file is part of GW-Android.

GW-Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GW-Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GW-Android. If not, see <http://www.gnu.org/licenses/>. */
package br.ufes.cwtools.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;

public abstract class Component extends Activity {
	public static final int RESULT_BACK = RESULT_FIRST_USER;
	
	protected ComApplication app;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.app = (ComApplication) this.getApplication();
	}
	
	@Override
	public void finish() {
		this.finish(RESULT_OK);
	}
	
	private void finish(int resultCode) {
		this.setResult(resultCode, this.getIntent());
		super.finish();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish(RESULT_BACK);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
